package com.huobao.yunying.adapters;

import java.util.List;

import com.huobao.yunying.entity.Goods_list;
import com.huobao.yunying.utils.ImageUtils;
import com.huobao.yunying.utils.ImageUtils.OnImageLoadListener;
import com.huobao.zhangying.R;
import com.xrz.sxm.base.utils.ScreenUtil;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import joanzapata.android.BaseAdapterHelper;
import joanzapata.android.QuickAdapter;

public class Adapter_ProgectGridView extends QuickAdapter<Goods_list> {


	public Adapter_ProgectGridView(Context context, List<Goods_list> data) {
		super(context, R.layout.item_progect_grid, data);
	}

	@Override
	protected void convert(BaseAdapterHelper helper, Goods_list data) {
		final ImageView imageView = helper.getView(R.id.imageview);
		TextView tv_name = helper.getView(R.id.tv_1);
		TextView tv_price = helper.getView(R.id.tv_2);
		ImageUtils.loadimg(imageView, data.getDefault_image(), new OnImageLoadListener() {

			@Override
			public void onLoadSuccess(Drawable drawable) {
				int newWidth =  ScreenUtil.getInstant().getDisWidth(context) / 2 - 20 ;
				int newHight = newWidth * drawable.getIntrinsicHeight()
						/ drawable.getIntrinsicWidth();
				LayoutParams params = (LayoutParams) imageView.getLayoutParams();
				params.width = newWidth;
				params.height = newHight;
				params.gravity = Gravity.CENTER_HORIZONTAL;
				params.setMargins(2, 2, 2, 2);
				imageView.setLayoutParams(params);
			}
		});
		tv_name.setText(data.getGoods_name());
		tv_price.setText("￥" + data.getPrice());
	}

}
